home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turn the Power On! 3
/
Turn the Power On! HP Volume III (HP)(1995).ISO
/
copy_files
next >
Wrap
Text File
|
1995-10-03
|
1KB
|
70 lines
#!/bin/ksh
# Do a cp -R after checking for room on the destination
set -u
PATH=$PATH:/etc
PWD=`pwd`
umask a=rwx
progname=`basename $0`
if [[ $# -ne 2 ]]
then
echo "usage: $progname sourcedir targetdir" >&2
exit 1
fi
source=$1
target=$2
if [[ ! -d $source ]]
then
echo "$progname: $source is not a readable directory" >&2
exit 2
fi
if [[ -d $target ]] # It's already there
then
if [[ ! -w $target ]]
then
echo "$progname: $target is not writeable by you" >&2
exit 3
fi
else # Try making it; if it's a normal file this will fail
mkdir -p $target >/dev/null 2>&1
if [[ $? -ne 0 ]]
then
echo "$progname: cannot create target directory $target">&2
exit 4
fi
fi
echo "Calculating space needed..." # du is not terribly fast
needed=`du -s $source | cut -f1`
# Use devnm to resolve the destination drive, then df it. df output
# for NFS mounts includes an extra colon so don't key on it.
echo "Calculating space available..."
targetdev=`devnm $target | cut -d' ' -f1`
available=`df $targetdev | cut -d')' -f2 | awk '{print $2}'`
if [[ $needed -gt $available ]]
then
echo "$progname: not enough room to copy everything" >&2
exit 5
fi
echo "Copying..." # Don't go verbose so that error messages can be seen
cd $source
find ./* -print | cpio -pdlm $target # no 'x', may not be root
echo "$progname: complete"
exit 0